home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / _TR_HTOI.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  723b  |  39 lines

  1. /*********
  2. *
  3. * _TR_HTOI.C
  4. *
  5. * by Ralph Davis
  6. *
  7. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  8. *
  9. * SYNTAX:  _tr_htoi(cp)
  10. *          char *cp;
  11. *
  12. * RETURN:  integer equivalent of cp
  13. *
  14. *********/
  15.  
  16. #include "trlib.h"
  17.    
  18. _tr_htoi(s)  /* dec() internal function */
  19. char *s;
  20. {
  21.    int hexdigit, i, n;
  22.  
  23.    n = 0;
  24.    for (i = 0; i < _tr_strlen(s); i++)
  25.    {
  26.       if (s[i] >= '0' && s[i] <= '9')
  27.           hexdigit = s[i] - '0';
  28.       else if (s[i] >= 'a' && s[i] <= 'f')
  29.           hexdigit = s[i] - 'a' + 10;
  30.       else if (s[i] >= 'A' && s[i] <= 'F')
  31.           hexdigit = s[i] - 'A' + 10;
  32.       else
  33.           return(0);
  34.       n = 16 * n + hexdigit;
  35.    }
  36.    return(n);
  37. }
  38.  
  39.